<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('合同审批列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目名称：</label>
                                <input type="text" autoComplete="off" name="projectName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:contract:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:contract:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-success single disabled" onclick="sqkpadd()" shiro:hasPermission="gcgl:sqkp:add">
                    <i class="fa fa-edit"></i> 开票申请
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:contract:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:contract:remove')}]];
        var againeditFlag = [[${@permission.hasPermi('system:contract:againedit')}]];
        var prefix = ctx + "sj/contract";
        var datas = [[${@dict.getType('sj_contract_type')}]];
        var datasstatus = [[${@dict.getType('sj_contract_status')}]];
        var datasgongs = [[${@dict.getType('sj_gongs')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                detailUrl: prefix + "/detail",
                modalName: "合同管理",
                sortName: "id desc",
                sortOrder: "",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'gcProjectId',
                    title: '项目ID',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '编号'
                },
                {
                    field: 'type',
                    title: '申报类别',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(datas, item.type);
		            }
                },
                {
                    field: 'projectName',
                    title: '项目名称'
                },
                {
                    field: 'htje',
                    title: '合同金额'
                },
                {
                    field: 'customerName',
                    title: '合同对方'
                },
                {
                    field: 'authorityName',
                    title: '项目所属'
                },
                {
                    field: 'owner',
                    title: '申报人'
                },
                {
                    field: 'dept',
                    title: '申报部门'
                },
                {
                    field: 'ztdw',
                    title: '主体公司',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(datasgongs, item.ztdw);
		            },
                    width: "90px"
                },
                {
                    field: 'status',
                    title: '状态',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(datasstatus, item.status);
		            }
                },
                {
                    title: '操作',
                    align: 'center',
                    width: "250px",
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.status==3){
                        	actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="zsht(\'' + row.id + '\')"><i class="fa fa-edit"></i>上传正式合同</a> ');
                        }
                        if(row.status==1){
                        	actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="run(\'' + row.processInstanceId + '\')"><i class="fa fa-file-archive-o"></i>流程进度</a>&nbsp;');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="licb(\'' + row.gcProjectId + '\')"><i class="fa fa-edit"></i>收款节点【里程碑】</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="print(\'' + row.id + '\')"><i class="fa fa-download"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + againeditFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>更正</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function print(id){
            $.modal.openTab('查看',"sj/contract/detail/"+id);
        }
        
        function run(processInstanceId) {
            $.modal.open("执行记录", ctx + "flow/monitor/historyDetail?processInstanceId=" + processInstanceId);
        }
        
        function traceProcess(processInstanceId) {
            $.modal.openTab("流程进度", ctx + "flow/monitor/traceProcess/"+processInstanceId);
        }
        
        function licb(id) {
            $.modal.openTab("收款节点【里程碑】", ctx + "sj/milestone/milestone/"+id);
        }
        
        function zsht(id) {
            $.modal.openTab("上传正式合同", ctx + "sj/contract/editZsht/"+id);
        }
        
        function sqkpadd() {
        	
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            var status = $.table.selectColumns("status");
            if(status>2){
            	$.modal.openTab('新增申请开票',"/gcgl/sqkp/add/"+rows.join());
            }else{
            	$.modal.alertWarning("该记录未审核通过！");
                return;
            }
        }
    </script>
</body>
</html>